package cn.edu.hnit.javaee.experiments.experiment02.service;

import java.time.LocalDateTime;
import java.util.List;

import cn.edu.hnit.javaee.experiments.experiment02.model.Player;
import cn.edu.hnit.javaee.experiments.experiment02.dao.GameActivityRepository;
import cn.edu.hnit.javaee.experiments.experiment02.model.GameActivity;


public class GameServiceImpl {
	 
    private GameActivityRepository gameActivityRepository;
	
	
	public int login(Player player, LocalDateTime now) {  
        
        // 查找当前正在进行的活动  
        List<GameActivity> currentActivities = gameActivityRepository.findActiveActivities(now);  
          
        // 如果有活动，则发送通知给玩家  
        if (!currentActivities.isEmpty()) {  
            for (GameActivity activity : currentActivities) {  
            	System.out.println("Sending activity notification to player " + player.getNickname() + ": " + activity.getTitle()); ;  
            }
            return currentActivities.size();
        } 
        return 0;
          
    } 
	
	public String sendPlayerMsg(Player player, String msg) {
		String result = String.format("[世界频道] [%s]:%s]", player.getNickname(),msg);
		System.out.println(result);
		return result;
	}
	
}
